<template>
    <template v-for="item in menusData" :key="item.id">
        <!-- 带有二级菜单 -->
        <el-sub-menu v-if="item.children" :index="item.path">
            <template #title>
                <el-icon v-if="item.icon">
                    <component :is="(icons as any)[item.icon]"></component>
                </el-icon>
                <span>{{ item.title }}</span>
            </template>
            <!-- 组件自己渲染自己 -->
            <SubMenu :menusData="item.children" />
        </el-sub-menu>

        <!-- 没有二级菜单 -->
        <el-menu-item v-else :index="item.path">
            <el-icon v-if="item.icon">
                <component :is="(icons as any)[item.icon]"></component>
            </el-icon>
            <span>{{ item.title }}</span>
        </el-menu-item>
    </template>
</template>

<script setup lang="ts">
import * as icons from '@element-plus/icons-vue';
import { ref } from 'vue';

 defineProps<{
    menusData:menuItem[]
}>()
// console.log(menusData);

</script>

<style scoped></style>